import Vue from 'vue'
import Vuex from 'vuex'
import dlqhttp from './common/http'

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		userInfo : {},
		menuList : [],
		systemName : '',
		URL : {
			upload : '/api/xagrid/upload',
		},
		//沈阳市中心点坐标
		center : [123.434,41.8057],
		city : '沈阳市',
		cityCode : '210100',
	},

	getters : {
		userInfo : state => state.userInfo,
		menuList : state => state.menuList,
		systemName : state => state.systemName,
		URL : state => state.URL,
		center : state => state.center,
		city : state => state.city,
		cityCode : state => state.cityCode,
	},

	mutations: {
		setUserInfo (state, obj) {
		    state.userInfo = obj;
		},
		setMenuList (state, obj) {
	        state.menuList = obj;
	    },
	    setSystemName (state, obj) {
	        state.systemName = obj;
	    },
	},

	actions: {
		getUserInfo ({ commit, dispatch}, para) {
			dlqhttp({
				fun : 'userInfo',
				//requestType : 'get',
				cb : res => {
					console.log(res);
					commit('setUserInfo', res);
				}
			});
		},

		getMenuList ({ commit, dispatch}, para) {
			dlqhttp({
				//mock: true,
				fun : 'menuList',
				menu_id : para.menu_id,
				cb : res => {
					console.log(res);
					res.forEach(item => {
						console.log(item.id);
						if(item.id == 'aa54d722-46ce-11e9-b3be-0242ac11001d'){
							commit('setMenuList', item.list);
							commit('setSystemName', item.name);
						}
					})
					
				}
			});
		},
	}
})
